import request from '@/utils/request.js'

const clientApi = {
  List: '/client/list',
  Add: '/client/add',
  Update: '/client/update',
  Delete: '/client/delete',
  getContactList: '/client/contactName'
}

const Map = {
  'ascend': 'asc',
  'descend': 'desc'
}
export function listClient (parameter) {
  return request({
    url: clientApi.List,
    method: 'get',
    params: {
      clientName: parameter.clientName || null, // 不传递空字符串
      contactName: parameter.contactName,
      createTime: parameter.createTime,
      page: parameter.page || 1,
      pageSize: parameter.pageSize || 10,
      order: Map[parameter.order] || 'asc'
    }
  })
}

export function addClient (parameter) {
  return request({
    url: clientApi.Add,
    method: 'post',
    data: parameter
  })
}

export function updateClient (parameter) {
  return request({
    url: clientApi.Update,
    method: 'put',
    data: parameter
  })
}

export function deleteClient (parameter) {
  return request({
    url: clientApi.Delete,
    method: 'delete',
    params: {
      id: parameter
    }
  })
}

export function getContactList () {
  return request({
    url: clientApi.getContactList,
    method: 'get'
  })
}
